trigger iFulfillUpdatePreview on Task (after insert) {
list<id> fItems = new list<id>();
list<fullfilment_item__c> previewItems = new list<fullfilment_item__c>();

for(Task tsk :trigger.new){
    if(tsk.whatid != null){
        string FId = tsk.whatid;
        if(FId.startswith(GeneralConstants.Fulfillment_Item_Prefix)){ //get the FI from which "Preview emails" have been sent
            if(tsk.Description != null && (tsk.Description.indexOf(IfullfillTextConstant.FI_PREVIEW_TEMPLATE )!= -1 ))
                fItems.add(tsk.whatid); 
        }
    }
}
system.debug('fItems->'+ fItems);
if(fItems.size() > 0) previewItems = [select Preview_Status__c ,Number_of_Rounds__c,Last_Round__c,First_Sent_Date__c from fullfilment_item__c where id in :fItems];

for(fullfilment_item__c FI : previewItems  ){ //update FI whenever "Preview email" has been sent
    FI.Preview_Status__c = IfullfillTextConstant.FI_PREVIEW_MAILSENT_STAT ;
    if(FI.Number_of_Rounds__c ==null)
        FI.Number_of_Rounds__c = '1';
    if(FI.Last_Round__c == null)
        FI.Last_Round__c = '1';
    if(FI.First_Sent_Date__c == null )
        FI.First_Sent_Date__c = system.now();
}

try {update previewItems; }
catch(dmlexception e){
generalconstants.mailAnyExceptionToMe('iFulfillUpdatePreview TRIGGER','iFulfillUpdatePreview',e);
}

}